package util

type Predictor[T any, P Ptr[T]] interface {
	Predict(P) bool
}

func FindP[T any, P Ptr[T]](list []T, pred Predictor[T, P]) (P, bool) {
	for i := range list {
		ptr := &list[i]
		if pred.Predict(ptr) {
			return ptr, true
		}
	}
	return nil, false
}

func Find[T any, P Ptr[T]](list []T, pred Predictor[T, P]) (T, bool) {
	var t T
	for i := range list {
		ptr := &list[i]
		if pred.Predict(ptr) {
			return *ptr, true
		}
	}
	return t, false
}
